const sharp = require('sharp');
export function minPng(outpng: string, png?): Promise<string> {
    return new Promise((resolve, reject) => {
        const fileArry = outpng.split('.');
        const filePath = fileArry[1];
        const min = `.${filePath}_min.${png ? 'png' : 'jpg'}`;
        // try {
        //     images(outpng) //Load image from file 
        //     .save(min, { //Save the image to a file, with the quality of 50
        //         quality: 50 //保存图片到文件,图片质量为50
        //     });
        // } catch (error) {
        //     debugger;
        // }
        sharp(outpng)
            .jpeg({ quality: 80 })
            // .resize({ width:tewrqS`z 800, height: 600 })
            .toFile(min, (err, info) => {
                if (err) {
                    console.error(err);
                    reject(err)
                } else {
                    console.log('压缩成功:', info);
                    resolve(min)
                }
            });
    })

}